<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>DAFeedback</title>
</head>
<body>
<!-- This is a simple script based on jrfeedback.php by Jonathan 'Wolf' Rentzsch. I have modified in for the purposes of demostrating Unit Testing techniques at the TACOW meeting April 14, 2009
Changed to log the feedback payload to a series of XML files rather than email, since the TACOW meeting often does not have internet access. -->
<!-- $Id: dafeedback.php 55 2009-04-14 01:26:50Z planbsoftware@me.com $ -->

<p>This page not intended for humans. Thanks for playing, though.</p>

<?php
	if (array_key_exists('feedback', $_REQUEST)) 
	{
		function uuid($prefix = '')
		{
			$chars = md5(uniqid(mt_rand(), true));
			$uuid  = substr($chars,0,8) . '-';
			$uuid .= substr($chars,8,4) . '-';
			$uuid .= substr($chars,12,4) . '-';
			$uuid .= substr($chars,16,4) . '-';
			$uuid .= substr($chars,20,12);
			return $prefix . $uuid;
		}

		$feedbackType = $_REQUEST['feedbackType'];
		$appName = $_REQUEST['appName'];
		$appVersion = $_REQUEST['version'];
		$bundleID = $_REQUEST['bundleID'];
		$feedback = $_REQUEST['feedback'];
		$email = $_REQUEST['email'];

		$content .= '<?xml version="1.0" ?>' . "\n";
		$content .= '<' . $feedbackType . '>' . "\n";
		$content .= '	<app version="' . $appVersion . '" id="' . $bundleID . '">' . $appName . '></app>' . "\n";
		$content .= '	<email>' . $email . '</email>' . "\n";
		$content .= '	<comments>' . $feedback . '</comments>' . "\n";
		$content .= '</' . $feedbackType . '>' . "\n";
		
		if ( ! file_exists( '/tmp/dafeedback' ))
		{
			mkdir( '/tmp/dafeedback');
		}
	
		$myFile = '/tmp/dafeedback/' . uuid() . '.xml';
		$file_handle = fopen($myFile, 'w') or die("can't open file");
		
		fwrite($file_handle, $content);
		fclose($file_handle);
	}
	else
	{
		print "No POST data\n\n";
	}
?>

</body>
</html>
